<?php
namespace app\home\controller;
use pidan\captcha\facade\Captcha;
use app\home\Controller;

class Tools extends Controller
{
	protected $app;
	public function verify()
	{
			#return (new Captcha($this->app->config,$this->app->session))->create();
			return Captcha::create();
	}
	public function sendEmailVerify()
	{
		$code=bin2hex(random_bytes(3));
		$email=input('request.email','','trim');
		session('email',$email);
		session('email_verify',$code);
		return $this->code(0,lang('be sent successfully').$code);
	}


	public function uploadImg()
	{
		//对应 <input name
		$field='myFile';

		$dirArr=['task/'];
		$dest=intval($_REQUEST['act']);			//上传到哪个主目录

		$uploads=public_path('uploads/tmp');
		if(in_array($dest,[0]) && isset($_FILES[$field]) && chk_files($_FILES[$field])) {//检查图片是否有上传
			$dest=$dirArr[$dest];

			$date_path=date('Ymd').'/';//图片保存路径
			$ext=strtolower(substr($_FILES[$field]['name'],strrpos($_FILES[$field]['name'],'.')));//扩展名

			//唯一临时文件名
			if(in_array($ext,array('.jpg', '.gif', '.png', '.jpeg', '.bmp','.webp'))){
				$name=random_name($uploads.$dest.$date_path,$ext);
				make_dir($uploads.$dest.$date_path);
				if(move_uploaded_file($_FILES[$field]['tmp_name'], $uploads.$dest.$date_path.$name)){
					$echo=$dest.$date_path.$name;
				}
			}
		}
		else{
			$echo='';
		}
		return $echo;
	}


}
